<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>16进制随机颜色</title>
    <script>
        function getRandomIntInclusive(min, max) {
            min = Math.ceil(min);
            max = Math.floor(max);
            return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值，含最小值 
        }
        function randomColor() {
            var colorArr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
            var colorStr = '#';
            for (var i = 0; i < 6; i++) {
                colorStr += colorArr[getRandomIntInclusive(0, 15)];
            }
            return colorStr;
        }
        console.log(randomColor());
    </script>
</head>

<body>

</body>

</html>